<?php
namespace app\common\model;
use app\common\model\CommonModel;
use think\Db;

class Order extends CommonModel
{
	/**
	* 添加订单信息
	*/
	public function serOrder($data)
	{
		return $this->insertGetId($data);
	}
    /**
    * 获取列表信息
    */
    public function orderList($where,$limit)
    {
        return $this->where($where)->order('addtime DESC')->paginate($limit);
    }
    /**
    * 连表查询
    */
    public function gorderList($where,$limit,$field,$group = 'o.order_id')
    {
        return $this->alias('o')
				->join('mps_order_goods g','o.order_id = g.order_id')
				->where($where)->field($field)
                ->group($group)
                ->order('addtime DESC')
                ->paginate($limit);
    }
    /**
    * 某个字段
    */
    public function gordercolumn($where,$field,$group = 'o.order_id')
    {
        return $this->alias('o')
				->join('mps_order_goods g','o.order_id = g.order_id')
				->where($where)->group($group)->column($field);
    }
    /**
    * 订单数量
    */
    public function orderCount($where)
    {
        return $this->alias('o')
				->join('mps_order_goods g','o.order_id = g.order_id')
				->where($where)->count();
    }
    /**
    * 金额计算
    */
    public function orderSum($where,$field)
    {
        return $this->alias('o')
				->join('mps_order_goods g','o.order_id = g.order_id')
				->where($where)->sum($field);
    }
    /**
    * 订单详情
    */
    public function orderInfo($where)
    {
        $item = $this->where($where)->find();
        return empty($item) ? array():$item->toArray();
    }
    /*
    *修改订单信息
    */
    public function updateOrder($where,$data)
	{
		return $this->where($where)->update($data);
	}
}

